package com.hyz.reggie.service.Impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hyz.reggie.dao.CategoryDao;
import com.hyz.reggie.pojo.*;
import com.hyz.reggie.service.CategoryService;
import com.hyz.reggie.service.DishService;
import com.hyz.reggie.service.SetmealService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryDao, Category> implements CategoryService {
    @Autowired
    private SetmealService setmealService;
    @Autowired
    private DishService dishService;

    @Override
    public void delete(Long id) {
        LambdaQueryWrapper<Setmeal> qwq1 = new LambdaQueryWrapper<>();
        qwq1.eq(Setmeal::getCategoryId, id);
        int count1 = setmealService.count(qwq1);
        if (count1 > 0) {
            throw new AcquireExecption("请先删除关联的套餐~");
        }
        LambdaQueryWrapper<Dish> qwq2 = new LambdaQueryWrapper<>();
        qwq2.eq(Dish::getCategoryId, id);
        int count2 = dishService.count(qwq2);
        if (count2 > 0) {
            throw new AcquireExecption("请先删除关联的菜品~");
        }
        super.removeById(id);
    }
}
